package com.ecoolex.discount.sales.core.manager;

import com.ecoolex.discount.sales.core.dao.YouWorldOrderRecordDAO;
import com.ecoolex.discount.sales.entity.YouWorldOrderRecord;
import com.ecoolex.discount.sales.entity.YouWorldOrderRecordExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Service
public class YouWorldOrderRecordManager {
    @Autowired
    private YouWorldOrderRecordDAO dao;

    public YouWorldOrderRecord save(YouWorldOrderRecord record){
        dao.insert(record);
        return record;
    }

    public Optional<YouWorldOrderRecord> getByOrderNo(String orderNo){
        YouWorldOrderRecordExample example =   YouWorldOrderRecordExample.newAndCreateCriteria()
                .andOrderNoEqualTo(orderNo).example();
        List<YouWorldOrderRecord> list = dao.selectByExample(example);
        if(!CollectionUtils.isEmpty(list)){
            return Optional.of(list.get(0));
        }
        return Optional.empty();
    }

    public void upate(YouWorldOrderRecord record ,YouWorldOrderRecord.Column ... selective){
        dao.updateByPrimaryKeySelective(record,selective);
    }
}